package com.example.skin_whitening_ndk;

import android.graphics.Bitmap;
import android.graphics.Color;

/**
 * Created by jiang at 2021/9/28
 */
public class javaBitmaoRotate {

    public Bitmap getImageBitmap(Bitmap src){
        int width=src.getWidth();
        int height=src.getHeight();
        Bitmap dst;
        if (width>=height){
             dst=Bitmap.createBitmap(width,width, Bitmap.Config.ARGB_8888);
        }else {
             dst=Bitmap.createBitmap(height,height, Bitmap.Config.ARGB_8888);
        }

        dst=ClockwiseRotate180(width,height,src,dst);

        return dst;
    }

    private Bitmap Copy(int width,int height ,Bitmap src,Bitmap dst){
        int Pixel_color;

        for (int x=0;x<width;x++){
            for (int y=0;y<height;y++){
                Pixel_color= src.getPixel(x,y);

                //原图拷贝
              dst.setPixel(x,y,Pixel_color);
                //图像镜像+旋转
                // dst.setPixel(y,x,Pixel_color);
            }
        }
        return dst;
    }

    private Bitmap ClockwiseRotate90(int width,int height ,Bitmap src,Bitmap dst){
        int Pixel_color;
        //依次拿到每一个像素点
        for (int x=0;x<width;x++){
            int Ymax=height;
            for (int y=0;y<height;y++){
                Pixel_color= src.getPixel(x,y);
                //图像顺时针90
                dst.setPixel(--Ymax,x,Pixel_color);
            }
        }
        return dst;
    }

    private Bitmap  AnticlockwiseRotate90(int width,int height ,Bitmap src,Bitmap dst){
        int Xmas=width;
        int Pixel_color;
        int Ymax=height;
        //依次拿到每一个像素点
        for (int x=0;x<width;x++){
                --Ymax;
            for (int y=0;y<height;y++){
                Pixel_color= src.getPixel(x,y);
                dst.setPixel(y,Ymax,Pixel_color);
            }

        }
        return dst;
    }

    private Bitmap  ClockwiseRotate180(int width,int height ,Bitmap src,Bitmap dst){
        int Xmas=width;
        int Pixel_color;
        int Ymax=height;
        //依次拿到每一个像素点
        for (int x=0;x<width;x++){
            --Xmas;
            Ymax=height;
            for (int y=0;y<height;y++){
                Pixel_color= src.getPixel(x,y);
                dst.setPixel(Xmas,--Ymax,Pixel_color);
            }
        }
        return dst;
    }
}
